package com.bestom.bluetoothlock.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.asm.Opcodes;
import com.bestom.bluetoothlock.LockApplication;
import com.bestom.bluetoothlock.R;
import com.bestom.bluetoothlock.bluetooth.BleServiceManage;
import com.bestom.bluetoothlock.bluetooth.BraceletInstructions;
import com.bestom.bluetoothlock.entity.DeviceInfo;
import com.bestom.bluetoothlock.entity.EventDevice;
import com.bestom.bluetoothlock.entity.ReceiveInfo;
import com.bestom.bluetoothlock.util.Constants;
import com.bestom.bluetoothlock.util.LogMsg;
import com.bestom.bluetoothlock.util.SharedPrefrencesHelper;
import com.bestom.bluetoothlock.util.ToastUtil;
import com.bestom.bluetoothlock.views.DeviceSettingDialog;
import com.bestom.bluetoothlock.views.InputDialog;
import com.bestom.bluetoothlock.views.SearchDialog;

import org.greenrobot.eventbus.EventBus;

import java.util.Date;
import java.util.TimeZone;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DeviceFunctionActivity extends BaseActivity {
    private static final int HANDLER_MESS_NOTIFY = 1;
    private static final int HANDLER_MESS_RECEIVE = 0;
    /* access modifiers changed from: private */
    public BleServiceManage bleManage;
    private int connectState = -1;
    /* access modifiers changed from: private */
    public DeviceInfo device;
    /* access modifiers changed from: private */
    public DeviceSettingDialog deviceSettingDialog;
    @SuppressLint("HandlerLeak")
    public Handler handler = new Handler() {
        public void handleMessage(Message message) {
            super.handleMessage(message);
        }
    };
    
    @SuppressLint("HandlerLeak")
    public Handler handlerListen = new Handler() {
        
        public void handleMessage(Message message) {
            super.handleMessage(message);
            if (DeviceFunctionActivity.this.searchDialog != null) {
                DeviceFunctionActivity.this.searchDialog.dismiss();
            }
            int i = message.what;
            int i2 = 1;
            if (i != 1) {
                switch (i) {
                    case 3:
                        ReceiveInfo receiveInfo = (ReceiveInfo) message.obj;
                        String cmd = receiveInfo.getCmd();
                        String result = receiveInfo.getResult();
                        if (cmd == null || !cmd.equals(BraceletInstructions.INSTRUCTIONS_CHANGE_LOCK_STATE)) {
                            if (cmd != null && cmd.equals(BraceletInstructions.INSTRUCTIONS_POWER)) {
                                String value = receiveInfo.getValue();
                                LogMsg.Mess("power:" + value);
                                int intValue = Integer.valueOf(value, 16).intValue();
                                LogMsg.Mess("powerNum:" + intValue);
                                if (result.equals("00")) {
                                    if (intValue >= 3810) {
                                        if (intValue >= 4200) {
                                            i2 = 100;
                                        } else if (intValue >= 4090) {
                                            i2 = (((intValue - 4090) * 5) / 110) + 95;
                                        } else if (intValue >= 3945) {
                                            i2 = (((intValue - 3945) * 15) / 145) + 80;
                                        } else {
                                            i2 = (((intValue - 3810) * 20) / 135) + 60;
                                        }
                                    } else if (intValue >= 3705) {
                                        i2 = (((intValue - 3705) * 20) / 105) + 40;
                                    } else if (intValue >= 3620) {
                                        i2 = (((intValue - 3620) * 20) / 90) + 20;
                                    } else if (intValue >= 3560) {
                                        i2 = (((intValue - 3560) * 10) / 60) + 10;
                                    } else if (intValue > 3500) {
                                        i2 = ((intValue - 3400) * 10) / Opcodes.IF_ICMPNE;
                                    }
                                    LockApplication.getSharedPreferencesHelper().saveInt("power_" + DeviceFunctionActivity.this.device.getLockmac(), i2);
                                    TextView textView = DeviceFunctionActivity.this.mBatteryText;
                                    textView.setText(i2 + "%");
                                    if (i2 <= 10) {
                                        DeviceFunctionActivity.this.mBatteryImg.setImageResource(R.drawable.bat0);
                                        return;
                                    } else if (i2 > 10 && i2 <= 40) {
                                        DeviceFunctionActivity.this.mBatteryImg.setImageResource(R.drawable.bat1);
                                        return;
                                    } else if (i2 > 40 && i2 <= 60) {
                                        DeviceFunctionActivity.this.mBatteryImg.setImageResource(R.drawable.bat2);
                                        return;
                                    } else if (i2 > 60 && i2 <= 90) {
                                        DeviceFunctionActivity.this.mBatteryImg.setImageResource(R.drawable.bat3);
                                        return;
                                    } else if (i2 > 90) {
                                        DeviceFunctionActivity.this.mBatteryImg.setImageResource(R.drawable.bat4);
                                        return;
                                    } else {
                                        return;
                                    }
                                } else {
                                    LogMsg.Mess("电量获取失败");
                                    return;
                                }
                            } else if (cmd == null || !cmd.equals("0d")) {
                                if (cmd == null || !cmd.equals(BraceletInstructions.INSTRUCTIONS_UNBIND)) {
                                    if (cmd == null || !cmd.equals(BraceletInstructions.INSTRUCTIONS_RESET_FINGER)) {
                                        if (cmd != null && cmd.equals(BraceletInstructions.INSTRUCTIONS_SYNC_TIME)) {
                                            boolean unused = DeviceFunctionActivity.this.synctime = false;
                                            return;
                                        }
                                        return;
                                    } else if (result != null && result.equals("00")) {
                                        if (DeviceFunctionActivity.this.unbind_flag) {
                                            DeviceFunctionActivity.this.bleManage.sendData(BraceletInstructions.unBindInstructions());
                                            return;
                                        }
                                        DeviceFunctionActivity.this.bleManage.sendData(BraceletInstructions.factoryResetInstructions());
                                        DeviceFunctionActivity.this.deviceSettingDialog.dismiss();
                                        DeviceFunctionActivity.this.resetLock();
                                        return;
                                    } else {
                                        return;
                                    }
                                } else if (result == null || !result.equals("00")) {
                                    ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.unbind_fail));
                                    return;
                                } else {
                                    DeviceFunctionActivity.this.deviceSettingDialog.dismiss();
                                    ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.unbind_success));
                                    DeviceFunctionActivity.this.unbindLock();
                                    return;
                                }
                            } else if (result == null || !result.equals("00")) {
                                ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.reset_fail));
                                return;
                            } else {
                                DeviceFunctionActivity.this.deviceSettingDialog.dismiss();
                                DeviceFunctionActivity.this.resetLock();
                                ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.reset_success));
                                return;
                            }
                        } else if (result != null && result.equals(BraceletInstructions.INSTRUCTIONS_CHANGE_LOCK_STATE)) {
                            DeviceFunctionActivity.this.tv_hint.setText(DeviceFunctionActivity.this.getString(R.string.click_close_lock_again));
                            LogMsg.Mess("开锁失败");
                            return;
                        } else if (result == null || !result.equals("00")) {
                            LogMsg.Mess("开锁失败");
                            return;
                        } else {
                            DeviceFunctionActivity.this.tv_hint.setText(DeviceFunctionActivity.this.getString(R.string.click_open_lock_again));
                            LogMsg.Mess("开锁成功");
                            return;
                        }
                    case 4:
                        if (((Boolean) message.obj).booleanValue()) {
                            DeviceFunctionActivity.this.handlerListen.postDelayed(new Runnable() {
                                public void run() {
                                    DeviceFunctionActivity.this.gainPower();
                                }
                            }, 500);
                            return;
                        }
                        return;
                    default:
                        return;
                }
            } else {
                if (DeviceFunctionActivity.this.searchDialog != null) {
                    DeviceFunctionActivity.this.searchDialog.dismiss();
                }
                if (((Boolean) message.obj).booleanValue()) {
                    DeviceFunctionActivity.this.mOnlineImg.setImageResource(R.drawable.online_icon);
                    DeviceFunctionActivity.this.mUnlockBtn.setBackgroundResource(R.drawable.unlock_btn_bg);
                    DeviceFunctionActivity.this.tv_connect_state.setText("已连接");
                    LogMsg.Mess("已连接");
                    DeviceFunctionActivity.this.tv_connect_state.setTextColor(DeviceFunctionActivity.this.getResources().getColor(R.color.color_DBDBDB));
                    DeviceFunctionActivity.this.iv_device_icon.setImageResource(R.drawable.iv_device_manage_lockconnect_icon);
                    DeviceFunctionActivity.this.gainPower();
                    return;
                }
                LogMsg.Mess("断开连接");
                DeviceFunctionActivity.this.mOnlineImg.setImageResource(R.drawable.offline_icon);
                DeviceFunctionActivity.this.mUnlockBtn.setBackgroundResource(R.drawable.unlock_btn_bg_s);
                DeviceFunctionActivity.this.tv_connect_state.setText("断开连接");
                DeviceFunctionActivity.this.tv_connect_state.setTextColor(DeviceFunctionActivity.this.getResources().getColor(R.color.color_A3AAA7));
                DeviceFunctionActivity.this.iv_device_icon.setImageResource(R.drawable.iv_device_manage_lockdisconnect_icon);
                ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.device_disconnect));
                DeviceFunctionActivity.this.bleManage.connect(DeviceFunctionActivity.this.device);
                DeviceFunctionActivity.this.finish();
            }
        }
    };
    /* access modifiers changed from: private */
    public InputDialog inputDialog;
    private boolean isFrist = true;
    private boolean isPower = false;
    @BindView(R.id.iv_device_icon)
    ImageView iv_device_icon;
    @BindView(R.id.iv_left)
    ImageView iv_left;
    @BindView(R.id.iv_right)
    ImageView iv_right;
    @BindView(R.id.ll_connect_state)
    LinearLayout ll_connect_state;
    @BindView(R.id.ll_fingerprint_setting)
    LinearLayout ll_fingerprint_setting;
    @BindView(R.id.ll_use_record)
    LinearLayout ll_use_record;
    private LockStateReceiver lockStateReceiver;
    @BindView(R.id.batteryImg)
    ImageView mBatteryImg;
    @BindView(R.id.batteryText)
    TextView mBatteryText;
    /* access modifiers changed from: private */
    public EditText mInputEdit;
    @BindView(R.id.online_img)
    ImageView mOnlineImg;
    /* access modifiers changed from: private */
    public Dialog mPasswordDialog;
    @BindView(R.id.unlockBtn)
    Button mUnlockBtn;
    /* access modifiers changed from: private */
    public EditText mVerifyEdit;
    /* access modifiers changed from: private */
    public SearchDialog searchDialog;
    /* access modifiers changed from: private */
    public boolean synctime = true;
    @BindView(R.id.tv_circle)
    TextView tv_circle;
    @BindView(R.id.tv_connect_state)
    TextView tv_connect_state;
    @BindView(R.id.tv_hint)
    TextView tv_hint;
    @BindView(R.id.tv_title)
    TextView tv_title;
    /* access modifiers changed from: private */
    public boolean unbind_flag = false;

    /* access modifiers changed from: protected */
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_device_function);
        ButterKnife.bind((Activity) this);
        this.device = (DeviceInfo) getIntent().getSerializableExtra(Constants.KEY_VALUE);
        initView();
        View inflate = View.inflate(this, R.layout.password, (ViewGroup) null);
        this.mInputEdit = (EditText) inflate.findViewById(R.id.inputEdit);
        this.mVerifyEdit = (EditText) inflate.findViewById(R.id.verifyEdit);
        this.mPasswordDialog = new AlertDialog.Builder(this, R.style.AlertDialog).setView(inflate).create();
    }

    private void initView() {
        this.iv_left.setVisibility(View.VISIBLE);
        this.iv_right.setVisibility(View.VISIBLE);
        this.iv_right.setImageResource(R.drawable.tab_setting);
        this.bleManage = BleServiceManage.getInstance(this);
        this.bleManage.setHandlerListener(this.handlerListen);
        if (this.device != null) {
            TextView textView = this.tv_title;
            textView.setText(LockApplication.getSharedPreferencesHelper().getString("name_" + this.device.getLockmac()));
            if (!this.bleManage.isConnect()) {
                showSearchDialog();
                this.bleManage.connect(this.device);
                return;
            }
            int i = LockApplication.getSharedPreferencesHelper().getInt("power_" + this.device.getLockmac());
            TextView textView2 = this.mBatteryText;
            textView2.setText(i + "%");
            if (i <= 10) {
                this.mBatteryImg.setImageResource(R.drawable.bat0);
            } else if (i > 10 && i <= 40) {
                this.mBatteryImg.setImageResource(R.drawable.bat1);
            } else if (i > 40 && i <= 60) {
                this.mBatteryImg.setImageResource(R.drawable.bat2);
            } else if (i > 60 && i <= 90) {
                this.mBatteryImg.setImageResource(R.drawable.bat3);
            } else if (i > 90) {
                this.mBatteryImg.setImageResource(R.drawable.bat4);
            }
        }
    }

    /* access modifiers changed from: private */
    public void gainPower() {
        this.isPower = true;
        this.bleManage.sendData(BraceletInstructions.getPowerInstructions());
    }

    /* access modifiers changed from: private */
    public void sendLockState() {
        this.bleManage.sendData(BraceletInstructions.lockStateInstructions());
    }

    public void OnSaveNameDoneClicked(View view) {
        String obj = this.mInputEdit.getText().toString();
        if (obj.equals("") || obj.length() != 6) {
            ToastUtil.toast(getResources().getString(R.string.please_input_password));
            return;
        }
        String obj2 = this.mVerifyEdit.getText().toString();
        if (obj2.equals("")) {
            ToastUtil.toast( getResources().getString(R.string.please_verify_password));
        } else if (!obj.equals(obj2)) {
            ToastUtil.toast( getResources().getString(R.string.please_verify_password));
        } else {
            LockApplication.getSharedPreferencesHelper().saveString("password_" + this.device.getLockmac(), obj);
            this.bleManage.setPassword(obj);
            this.mPasswordDialog.dismiss();
        }
    }

    /* access modifiers changed from: private */
    public void showSearchDialog() {
        if (this.searchDialog == null) {
            this.searchDialog = new SearchDialog(this);
        }
        this.searchDialog.show();
        this.searchDialog.setTitle(getString(R.string.connecting));
        Window window = this.searchDialog.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = -1;
        window.setAttributes(attributes);
        new Handler().postDelayed(new Runnable() {
            public void run() {
                DeviceFunctionActivity.this.searchDialog.dismiss();
            }
        }, 5000);
    }

    private void settingDialog() {
        if (this.deviceSettingDialog == null) {
            this.deviceSettingDialog = new DeviceSettingDialog(this);
        }
        this.deviceSettingDialog.show();
        this.deviceSettingDialog.setOnChangeClickListener(new DeviceSettingDialog.OnChangeClickListener() {
            public void onChangeClick(View view) {
                DeviceFunctionActivity.this.showChangeDialog();
            }
        });
        this.deviceSettingDialog.setOnChangePasswordClickListener(new DeviceSettingDialog.OnChangePasswordClickListener() {
            public void onChangeClick(View view) {
                if (DeviceFunctionActivity.this.device != null) {
                    EditText access$1100 = DeviceFunctionActivity.this.mInputEdit;
                    SharedPrefrencesHelper sharedPrefrencesHelper = LockApplication.getSharedPreferencesHelper();
                    access$1100.setText(sharedPrefrencesHelper.getString("password_" + DeviceFunctionActivity.this.device.getLockmac()));
                    EditText access$1200 = DeviceFunctionActivity.this.mVerifyEdit;
                    SharedPrefrencesHelper sharedPrefrencesHelper2 = LockApplication.getSharedPreferencesHelper();
                    access$1200.setText(sharedPrefrencesHelper2.getString("password_" + DeviceFunctionActivity.this.device.getLockmac()));
                    DeviceFunctionActivity.this.mPasswordDialog.show();
                }
            }
        });
        this.deviceSettingDialog.setOnUnbindClickListener(new DeviceSettingDialog.OnUnbindClickListener() {
            public void onUnbindClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(DeviceFunctionActivity.this);
                if (DeviceFunctionActivity.this.bleManage.isConnect()) {
                    builder.setMessage(DeviceFunctionActivity.this.getResources().getString(R.string.sure_to_unbind));
                } else {
                    builder.setMessage(DeviceFunctionActivity.this.getResources().getString(R.string.sure_to_unbind_force));
                }
                builder.setPositiveButton(DeviceFunctionActivity.this.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        if (DeviceFunctionActivity.this.bleManage.isConnect()) {
                            DeviceFunctionActivity.this.showSearchDialog();
                            boolean unused = DeviceFunctionActivity.this.unbind_flag = true;
                            DeviceFunctionActivity.this.bleManage.sendData(BraceletInstructions.resetFingerInstructions());
                            return;
                        }
                        DeviceFunctionActivity.this.unbindLock();
                    }
                });
                builder.setNegativeButton(DeviceFunctionActivity.this.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                builder.create().show();
            }
        });
        this.deviceSettingDialog.setOnResetClickListener(new DeviceSettingDialog.OnResetClickListener() {
            public void onResetClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(DeviceFunctionActivity.this);
                builder.setMessage(DeviceFunctionActivity.this.getResources().getString(R.string.sure_to_reset));
                builder.setPositiveButton(DeviceFunctionActivity.this.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        if (DeviceFunctionActivity.this.bleManage.isConnect()) {
                            DeviceFunctionActivity.this.showSearchDialog();
                            boolean unused = DeviceFunctionActivity.this.unbind_flag = false;
                            DeviceFunctionActivity.this.bleManage.sendData(BraceletInstructions.resetFingerInstructions());
                            return;
                        }
                        ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.not_connected_bluetooth));
                    }
                });
                builder.setNegativeButton(DeviceFunctionActivity.this.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                builder.create().show();
            }
        });
    }

    /* access modifiers changed from: private */
    public void showChangeDialog() {
        if (this.device != null) {
            if (this.inputDialog == null) {
                this.inputDialog = new InputDialog(this);
            }
            this.inputDialog.show();
            this.inputDialog.setTitle(getString(R.string.change_device_name));
            this.inputDialog.setOnConfirmClickListener(new InputDialog.OnConfirmClickListener() {
                public void onConfirmClick(View view) {
                    String content = DeviceFunctionActivity.this.inputDialog.getContent();
                    if (TextUtils.isEmpty(content)) {
                        ToastUtil.toast(DeviceFunctionActivity.this.getString(R.string.please_input_device_name));
                        return;
                    }
                    SharedPrefrencesHelper sharedPrefrencesHelper = LockApplication.getSharedPreferencesHelper();
                    sharedPrefrencesHelper.saveString("name_" + DeviceFunctionActivity.this.device.getLockmac(), content);
                    EventBus.getDefault().post(new EventDevice(1));
                    DeviceFunctionActivity.this.tv_title.setText(content);
                    DeviceFunctionActivity.this.deviceSettingDialog.dismiss();
                }
            });
        }
    }

    /* access modifiers changed from: private */
    public void resetLock() {
        SharedPrefrencesHelper sharedPrefrencesHelper = LockApplication.getSharedPreferencesHelper();
        sharedPrefrencesHelper.saveInt("finger_count_" + this.device.getLockmac(), 0);
    }

    /* access modifiers changed from: private */
    public void unbindLock() {
        boolean z;
        int i = LockApplication.getSharedPreferencesHelper().getInt("count");
        int i2 = -1;
        if (i > 0) {
            z = false;
            int i3 = -1;
            for (int i4 = 0; i4 < i; i4++) {
                if (LockApplication.getSharedPreferencesHelper().getString("mac" + i4).equals(this.device.getLockmac())) {
                    i3 = i4;
                    z = true;
                }
            }
            i2 = i3;
        } else {
            z = false;
        }
        if (z) {
            int i5 = i - 1;
            if (i2 != i5) {
                while (i2 < i5) {
                    String str = "mac" + i2;
                    StringBuilder sb = new StringBuilder();
                    sb.append("mac");
                    i2++;
                    sb.append(i2);
                    LockApplication.getSharedPreferencesHelper().saveString(str, LockApplication.getSharedPreferencesHelper().getString(sb.toString()));
                }
            }
            LockApplication.getSharedPreferencesHelper().saveInt("finger_count_" + this.device.getLockmac(), 0);
            LockApplication.getSharedPreferencesHelper().saveBoolean("registered_" + this.device.getLockmac(), false);
            LockApplication.getSharedPreferencesHelper().saveString("name_" + this.device.getLockmac(), "");
            LockApplication.getSharedPreferencesHelper().saveInt("count", i5);
        }
        this.bleManage.disConnect();
        EventBus.getDefault().post(new EventDevice(1));
        finish();
    }

    @OnClick({R.id.iv_left, R.id.iv_right, R.id.ll_fingerprint_setting, R.id.ll_use_record, R.id.tv_circle})
    public void onClickView(View view) {
        switch (view.getId()) {
            case R.id.iv_left:
                finish();
                return;
            case R.id.iv_right:
                settingDialog();
                return;
            case R.id.ll_fingerprint_setting:
                Intent intent = new Intent(this, FingerprintSettingActivity.class);
                intent.putExtra(Constants.KEY_VALUE, this.device);
                startActivity(intent);
                return;
            case R.id.ll_use_record:
                Intent intent2 = new Intent(this, UseRecordActivity.class);
                intent2.putExtra(Constants.KEY_VALUE, this.device);
                startActivity(intent2);
                return;
            case R.id.tv_circle:
                if (!this.bleManage.isConnect()) {
                    showSearchDialog();
                    this.bleManage.connect(this.device);
                    return;
                }
                this.bleManage.sendData(BraceletInstructions.changeLockStateInstructions());
                return;
            default:
        }
    }

    private class LockStateReceiver extends BroadcastReceiver {
        private LockStateReceiver() {
        }

        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.INTENT_ACITON_LOCK_STATE) && DeviceFunctionActivity.this.handler != null) {
                DeviceFunctionActivity.this.handler.postDelayed(new Runnable() {
                    public void run() {
                        DeviceFunctionActivity.this.sendLockState();
                    }
                }, 300);
            }
        }
    }

    public void OnUnlockClicked(View view) {
        if (!this.bleManage.isConnect()) {
            showSearchDialog();
            this.bleManage.connect(this.device);
            return;
        }
        this.bleManage.sendData(BraceletInstructions.changeLockStateInstructions());
    }

    public void onResume() {
        BleServiceManage bleServiceManage;
        super.onResume();
        Handler handler2 = this.handlerListen;
        if (handler2 != null && (bleServiceManage = this.bleManage) != null) {
            bleServiceManage.setHandlerListener(handler2);
            if (this.bleManage.isConnect()) {
                this.mOnlineImg.setImageResource(R.drawable.online_icon);
                this.mUnlockBtn.setBackgroundResource(R.drawable.unlock_btn_bg);
                this.tv_connect_state.setText("已连接");
                this.tv_connect_state.setTextColor(getResources().getColor(R.color.color_DBDBDB));
                this.iv_device_icon.setImageResource(R.drawable.iv_device_manage_lockconnect_icon);
                if (this.synctime) {
                    Date date = new Date(System.currentTimeMillis());
                    Log.d("agui", "default hour:" + date.getHours());
                    int offset = TimeZone.getDefault().getOffset(System.currentTimeMillis()) - TimeZone.getTimeZone("GMT").getRawOffset();
                    Log.d("agui", "offset:" + offset);
                    Date date2 = new Date(date.getTime() - ((long) offset));
                    Log.d("agui", "gmt hour:" + date2.getHours());
                    this.bleManage.sendData(BraceletInstructions.syncTimeInstructions(String.format("%02x%02x%02x%02x%02x%02x%02x", new Object[]{Integer.valueOf(date2.getYear() + -100), Integer.valueOf(date2.getMonth() + 1), Integer.valueOf(date2.getDate()), Integer.valueOf(date2.getHours()), Integer.valueOf(date2.getMinutes()), Integer.valueOf(date2.getSeconds()), 0})));
                    return;
                }
                return;
            }
            this.mOnlineImg.setImageResource(R.drawable.offline_icon);
            this.mUnlockBtn.setBackgroundResource(R.drawable.unlock_btn_bg_n);
            this.tv_connect_state.setText("断开连接");
            this.tv_connect_state.setTextColor(getResources().getColor(R.color.color_A3AAA7));
            this.iv_device_icon.setImageResource(R.drawable.iv_device_manage_lockdisconnect_icon);
            this.tv_circle.setText("0%");
        }
    }
}
